#include "UploadThread.h"


UploadThread::UploadThread(void)
{
}


UploadThread::~UploadThread(void)
{
}

void UploadThread::Worker()
{
	fseek(m_pf, 01, SEEK_END);
	m_nTotalByte = ftell(m_pf) - 1;
	fseek(m_pf, 0, SEEK_SET);

	int n, totN;

	SetProgressBar(m_nTotalByte);
	m_nAccuByte = 0;

	while (!feof(m_pf))
	{
		n = 0;
		totN = 0;
		if ((m_nReadByte = fread(m_cFileBuf, sizeof(char),4096, m_pf)) <= 0)
			break;
sendagain:
		n = send(m_nSocket, m_cFileBuf + totN, m_nReadByte - totN, 0);
		totN += n;
		if (totN < m_nReadByte)
		{
			goto sendagain;
		}
		m_nAccuByte += totN;
		m_pkProgressCtrl->SetPos(m_nAccuByte);
	}
	Close();
	AfxMessageBox("File Transfer has done");
	Stop();
}